﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FeatureServer.Modules
{
    public class StatesCitiesRivers_FeatureLayer:Nancy.NancyModule
    {
        public StatesCitiesRivers_FeatureLayer()
            : base("/rest/services/StatesCitiesRivers/FeatureServer/0")
        {
            Get["/"]=parameters=>
            {
                var color = new List<int>();
                color.Add(156);
                color.Add(173);
                color.Add(0);
                color.Add(255);

                var outline = new GISServer.Core.Client.Symbols.Outline
                {
                    Color = color,
                    Width = 1
                };

                var symbol = new GISServer.Core.Client.Symbols.SimpleMarkerSymbol
                {
                    Type = "esriSMS",
                    Style = "esriSMSCircle",
                    Color = color,
                    Size = 4,
                    Angle = 0,
                    Xoffset = 0,
                    Yoffset = 0,
                    Outline = outline
                };



                var lyr = new GISServer.Core.Client.LayerOrTable
                {
                    CurrentVersion = 1.1,
                    Id = 0,
                    Name = "Cities",
                    Type = "Feature Layer",
                    Description = "This service presents census information for U.S",
                    DefinitionExpression = "",
                    GeometryType = "esriGeometryPoint",
                    CopyrightText = "(c)",
                    ParentLayer = null,
                    SubLayers = null,
                    MinScale = 0,
                    MaxScale = 0,
                    DefaultVisibility = true,
                    Extent = new GISServer.Core.Client.Geometry.Envelope(-158.064605712891, 19.6961498260498, -67.986768734036, 64.8691042579708, 4326),
                    HasAttachments = false,
                    HtmlPopupType = "esriServerHTMLPopupTypeNone",
                    DrawingInfo = new GISServer.Core.Client.DrawingInfo
                    {
                        Renderer = new GISServer.Core.Client.SimpleRenderer
                        {
                            Type = "simple",
                            Symbol = symbol,
                            Label = "",
                            Description = ""
                        },
                        Transparency = 0,
                        LabelingInfo = null
                    }
                };
                lyr.DisplayField = "CITY_NAME";
                lyr.Fields = new List<GISServer.Core.Client.Field>();
                lyr.Fields.Add(new GISServer.Core.Client.Field("FID", "esriFieldTypeOID","FID"));
                lyr.Fields.Add(new GISServer.Core.Client.Field("Shape", "esriFieldTypeGeometry", "Shape"));
                lyr.Fields.Add(new GISServer.Core.Client.Field("CITY_FIPS", "esriFieldTypeString", "FIPS",5));
                lyr.Fields.Add(new GISServer.Core.Client.Field("CITY_NAME", "esriFieldTypeString", "CITY_NAME", 40));
                lyr.Fields.Add(new GISServer.Core.Client.Field("STATE_FIPS", "esriFieldTypeString", "STATE_FIPS", 2));
                lyr.Fields.Add(new GISServer.Core.Client.Field("STATE_NAME", "esriFieldTypeString", "STATE_NAME", 25));
                lyr.Fields.Add(new GISServer.Core.Client.Field("STATE_CITY", "esriFieldTypeString", "STATE_CITY", 7));
                lyr.Fields.Add(new GISServer.Core.Client.Field("TYPE", "esriFieldTypeString", "TYPE", 25));
                lyr.TypeIdField = null;
                lyr.Types = null;
                lyr.Relationships = new List<object>();
                lyr.Capabilities = "Map,Query,Data";

                //var str = "{\"currentVersion\":10.01,\"serviceDescription\":\"This worldwidemap, Esri (Thailand), TomTom, 2012\",\"layers\":[{\"id\":0,\"name\":\"World Street Map\",\"parentLayerId\":-1,\"defaultVisibility\":true,\"subLayerIds\":null,\"minScale\":0,\"maxScale\":0}],\"tables\":[],\"spatialReference\":{\"wkid\":102100},\"singleFusedMapCache\":true,\"tileInfo\":{\"rows\":256,\"cols\":256,\"dpi\":96,\"format\":\"JPEG\",\"compressionQuality\":90,\"origin\":{\"x\":-20037508.342787,\"y\":20037508.342787},\"spatialReference\":{\"wkid\":102100},\"lods\":[{\"level\":0,\"resolution\":156543.033928,\"scale\":591657527.591555},{\"level\":1,\"resolution\":78271.5169639999,\"scale\":295828763.795777},{\"level\":2,\"resolution\":39135.7584820001,\"scale\":147914381.897889},{\"level\":3,\"resolution\":19567.8792409999,\"scale\":73957190.948944},{\"level\":4,\"resolution\":9783.93962049996,\"scale\":36978595.474472},{\"level\":5,\"resolution\":4891.96981024998,\"scale\":18489297.737236},{\"level\":6,\"resolution\":2445.98490512499,\"scale\":9244648.868618},{\"level\":7,\"resolution\":1222.99245256249,\"scale\":4622324.434309},{\"level\":8,\"resolution\":611.49622628138,\"scale\":2311162.217155},{\"level\":9,\"resolution\":305.748113140558,\"scale\":1155581.108577},{\"level\":10,\"resolution\":152.874056570411,\"scale\":577790.554289},{\"level\":11,\"resolution\":76.4370282850732,\"scale\":288895.277144},{\"level\":12,\"resolution\":38.2185141425366,\"scale\":144447.638572},{\"level\":13,\"resolution\":19.1092570712683,\"scale\":72223.819286},{\"level\":14,\"resolution\":9.55462853563415,\"scale\":36111.909643},{\"level\":15,\"resolution\":4.77731426794937,\"scale\":18055.954822},{\"level\":16,\"resolution\":2.38865713397468,\"scale\":9027.977411},{\"level\":17,\"resolution\":1.19432856685505,\"scale\":4513.988705},{\"level\":18,\"resolution\":0.597164283559817,\"scale\":2256.994353},{\"level\":19,\"resolution\":0.298582141647617,\"scale\":1128.497176}]},\"initialExtent\":{\"xmin\":-36102993.745354,\"ymin\":-24068662.4969027,\"xmax\":36102993.745354,\"ymax\":24068662.4969027,\"spatialReference\":{\"wkid\":102100}},\"fullExtent\":{\"xmin\":-20037507.0671618,\"ymin\":-19971868.8804086,\"xmax\":20037507.0671618,\"ymax\":19971868.8804086,\"spatialReference\":{\"wkid\":102100}},\"units\":\"esriMeters\",\"supportedImageFormatTypes\":\"PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,AI,BMP\",\"documentInfo\":{\"Title\":\"World Street Map\",\"Author\":\"Esri\",\"Comments\":\"\",\"Subject\":\"streets, highways, major roads, railways, water features, administrative boundaries, cities, parks, protected areas, landmarks \",\"Category\":\"transportation(Transportation Networks) \",\"Keywords\":\"World, Global, Europe, Japan, Hong Kong, North America, United States, Canada, Mexico, Southern Africa, Asia, South America, Australia, New Zealand, Argentina, Brazil, Chile, Venezuela, Andorra, Austria, Belgium, Czech Republic, Denmark, France, Germany, Great Britain, Greece, Hungary, Ireland, Italy, Luxembourg, Netherlands, Norway, Poland, Portugal, San Marino, Slovakia, Spain, Sweden, Switzerland, Russia, Thailand, Turkey, 2012\",\"Credits\":\"Sources: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012\"},\"capabilities\":\"Map\"}";
                return Services.Utilities.GetJsonResponseObject(lyr.ToJson());
                //return Services.Utilities.GetJsonResponseObject(str);
            };
        }
    }
}